package com.wiretap.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.wiretap.po.Administrator;
import com.wiretap.util.Constants;

public class WiretapActionSupport extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {

	/**
	 * 序列號
	 */
	private static final long serialVersionUID = 7346958706279798803L;
	// 請求
	protected HttpServletRequest request;
	// 响应
	protected HttpServletResponse response;
	// 会话
	protected Map<String, Object> session;

	/**
	 * @return the session
	 */
	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	protected boolean isSuperAdmin() {
		Object obj = session.get(Constants.SESSION_USER);
		if (obj != null && obj instanceof Administrator) {
			Administrator admin = (Administrator) obj;
			return admin.isSuperAdmin();
		}
		return false;
	}

	protected String getAdminUsername() {
		Object obj = session.get(Constants.SESSION_USER);
		if (obj != null && obj instanceof Administrator) {
			Administrator admin = (Administrator) obj;
			return admin.getUsername();
		}
		return "@@@";
	}

}
